import * as echarts from 'echarts'
import { divide } from 'lodash'
export function bingtu(dataset) {
  return {
    color: dataset.color,
    series: {
      type: 'pie',
      // radius: ['47%', '87%'],
      radius: [0, '60%'],
      avoidLabelOverlap: false,
      // hoverOffset: 6,
      hoverAnimation: true,
      minAngle: 10,
      label: {
        normal: {
          show: false,
          position: 'outside',
          formatter: function (value) {
            let str = ''
            if (value.name.length > 4) {
              str += `{a|${dealName(value.name)}\n}{b|${value.data[dataset.dimensions[1]]}}{c|${dataset.series[0].unit}}`
            } else {
              str += `{a|${value.name}\n}{b|${value.data[dataset.dimensions[1]]}}{c|${dataset.series[0].unit}}`
            }
            return str
          },
          rich: {
            a: {
              color: '#1A1A1A',
              fontSize: 11,
              lineHeight: 20
            },
            b: {
              color: '#1A1A1A',
              fontSize: 15,
              lineHeight: 16
            },
            c: {
              color: ' #434343',
              fontSize: 11,
              lineHeight: 12
            },
          }
        },
        emphasis: {
          show: true,
          textStyle: {
            fontSize: '12',
            color: '#999999',
          },
          itemStyle: {
            shadowBlur: 0
          },
        }
      },
      labelLine: {
        show: true,
      }
    },
    dataset: dataset
  }
}

function dealName(val) {
  let str = val.slice(0, 4)
  return str + '...'
}
//横向柱状图
export function hengzhutu(dataset) {
  let legendL = 0
  dataset.dimensions.forEach((val, index) => {
    if (val.length > legendL && index > 0) legendL = val.length
  })
  let color = ['#2574FA', '#FAA922', '#6DC9F6', 'rgba(156, 242, 237, 1)', 'rgba(109, 201, 246, 1)']
  let series = []
  dataset.series.forEach((val, index) => {
    series.push({
      type: val.type,
      smooth: false,
      symbol: 'circle',
      barGap: '0%',
      barMaxWidth: 18,
      stack: dataset.series.stack ? dataset.series.stack : '',
      // tooltip: {
      //   show: false,
      //   valueFormatter: function (value) {
      //     return (value?value:'0') + val.unit;
      //   }
      // },
      itemStyle: {
        normal: {
          barBorderRadius: [4, 4, 4, 4],
          label: {
            show: true,
            position: "right",
            formatter: function (p) {
              // let str = `<br/>${p.data[p.seriesName]}${dataset.series[0].unit}`
              let str = `{a| ${p.data[p.seriesName]}${dataset.series[0].unit}}`
              return p.data[p.seriesName] ? str : '';
            },
            rich: {
              a: {
                color: '#000',
                padding: [0, 4, 0, 0],
                // fontFamily: ['numbers'],
                fontSize: 12,
                height: 22,
                borderRadius: 4,
                borderWidth: 1,
                borderColor: '#eeeeee'
              },
              b: {
                color: '#000',
              }
            },
          }
        }
      },

      lineStyle: {
        width: 2
      }
    })
  })
  return {
    color: ['#2574F9'],
    legend: {
      itemWidth: 10,
      show: dataset.dimensions.length > 2 ? true : false,
      left: 'center',
      bottom: 0,
      itemHeight: dataset.dimensions.length > 2 ? 3 : 15,
      textStyle: {
        color: '#000',
        width: 1,
        fontSize: legendL > 12 ? 10 : 12
      },
    },
    // dataZoom: [{type: 'inside',realtime: true,start: 0,end: 70}],
    tooltip: {
      trigger: 'axis',
      show: true,
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: '#434343',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
      position: function (pos) {
        return [10, pos[1],]
      },
      fontFamily: 'numbers',
      extraCssText: 'z-index: 0;box-shadow: 0 3px 10px 0px rgba(37,116,250,0.1);border-radius: 6px',
      formatter: function (params) {
        let str = ''
        if (params.length) {
          str = params[0].name
          params.forEach((val, index) => {
            str += `<br /> ${val.seriesName}: <span style="font-family: 'numbers';color:'#1A1A1A';">${val.data[val.seriesName] ? val.data[val.seriesName] : '0'}</span>${(dataset.series[val.seriesIndex].unit && dataset.series[val.seriesIndex].unit !== 'null' ? dataset.series[val.seriesIndex].unit : '')}`
          })
        } else {
          str += params.name
          str += `<br /> ${params.seriesName}: <span style="font-family: 'numbers';color:'#1A1A1A';">${params.data[params.seriesName] ? params.data[params.seriesName] : '0'}</span>${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}`
        }
        return str
      },
    },
    grid: {
      show: true,
      x: 0,
      y: 14,
      x2: 80,
      y2: 0,
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    xAxis: {
      splitNumber: 5,
      type: 'value',
      axisLabel: {
        color: '#BDBDBE',
        rotate: 50,
        show: false,
        interval: 0,
        textStyle: {
          color: '#999999',
          fontSize: '12',
        },
        formatter: '{a|{value}}',
        rich: {
          a: {
            fontFamily: 'numbers',
          },
        },
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        },
      },
      axisTick: {
        alignWithLabel: false,
        show: false
      },
      splitLine: { //网格线
        lineStyle: {
          type: 'dashed', //设置网格线类型 dotted：虚线 solid:实线
          color: "#eeeeee",
        },
        show: false //隐藏或显示
      }
    },
    yAxis: {
      type: 'category',
      axisLine: {
        show: false,
        lineStyle: {
          // color: '#f3f4f5',
          color: 'rgba(238, 238, 238, 1)'
        },
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        textStyle: {
          color: '#666666',
        },
        formatter: function (params) {
          var newParamsName = "";
          var paramsNameNumber = params.length;
          var provideNumber = 10;  //一行显示几个字
          var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
          if (paramsNameNumber > provideNumber) {
            for (var p = 0; p < rowNumber; p++) {
              var tempStr = "";
              var start = p * provideNumber;
              var end = start + provideNumber;
              if (p == rowNumber - 1) {
                tempStr = params.substring(start, paramsNameNumber);
              } else {
                tempStr = params.substring(start, end) + "\n";
              }
              newParamsName += tempStr;
            }

          } else {
            newParamsName = params;
          }
          return newParamsName
        },
      },
    },
    axisLabel: {
      // color: '#BDBDBE',
      show: true,
      interval: 0,
      textStyle: {
        color: '#999999',
        fontSize: '10'
      },
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#f3f4f5',
      },
    },
    axisTick: {
      alignWithLabel: true,
      show: false
    },
    series: series,
    dataset: dataset
  }
}
export function hengzhutu3(dataset) {
  let legendL = 0
  dataset.dimensions.forEach((val, index) => {
    if (val.length > legendL && index > 0) legendL = val.length
  })
  let color = ['#2574FA', '#FAA922', '#6DC9F6', 'rgba(156, 242, 237, 1)', 'rgba(109, 201, 246, 1)']
  let series = []
  dataset.series.forEach((val, index) => {
    series.push({
      type: val.type,
      smooth: false,
      symbol: 'circle',
      barGap: '0%',
      barMaxWidth: 10,
      barGap: index>0?'-100%':'',
      z: index>0?'-1':'',
      stack: dataset.series.stack ? dataset.series.stack : '',
      // tooltip: {
      //   show: false,
      //   valueFormatter: function (value) {
      //     return (value?value:'0') + val.unit;
      //   }
      // },
      lineStyle: {
        width: 2
      }
    })
  })
  return {
    color: ['#2574F9','#D9E9FF'],
    label: {
      show: true,
      formatter: '{b}',
      position: 'left',
      align: 'left',
      offset: [5, -14],
      color: '#8BA5E1',
      fontSize: 11,
      lineHeight: 15
    },
    // dataZoom: [{type: 'inside',realtime: true,start: 0,end: 70}],
    tooltip: {
      trigger: 'axis',
      show: true,
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: '#434343',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
      position: function (pos) {
        return [10, pos[1],]
      },
      fontFamily: 'numbers',
      extraCssText: 'z-index: 0;box-shadow: 0 3px 10px 0px rgba(37,116,250,0.1);border-radius: 6px',
      formatter: function (params) {
        let str = ''
        if (params.length) {
          str = params[0].name
          params.forEach((val, index) => {
            str += `<br /> ${val.seriesName}: <span style="font-family: 'numbers';color:'#1A1A1A';">${val.data[val.seriesName] ? val.data[val.seriesName] : '0'}</span>${(dataset.series[val.seriesIndex].unit && dataset.series[val.seriesIndex].unit !== 'null' ? dataset.series[val.seriesIndex].unit : '')}`
          })
        } else {
          str += params.name
          str += `<br /> ${params.seriesName}: <span style="font-family: 'numbers';color:'#1A1A1A';">${params.data[params.seriesName] ? params.data[params.seriesName] : '0'}</span>${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}`
        }
        return str
      },
    },
    grid: {
      left:'26',
      top:'10',
      bottom:'10',
      show: true,
      x: 0,
      y: 0,
      x2: 0,
      y2: 0,
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    xAxis: {
      splitNumber: 5,
      type: 'value',
      axisLabel: {
        color: '#BDBDBE',
        rotate: 50,
        show: false,
        interval: 0,
        textStyle: {
          color: '#999999',
          fontSize: '12',
        },
        formatter: '{a|{value}}',
        rich: {
          a: {
            fontFamily: 'numbers',
          },
        },
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        },
      },
      axisTick: {
        alignWithLabel: false,
        show: false
      },
      splitLine: { //网格线
        lineStyle: {
          type: 'dashed', //设置网格线类型 dotted：虚线 solid:实线
          color: "#eeeeee",
        },
        show: false //隐藏或显示
      }
    },
    yAxis: {
      type: 'category',
      axisLine: {
        show: false,
        lineStyle: {
          // color: '#f3f4f5',
          color: 'rgba(238, 238, 238, 1)'
        },
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        show: false,
        textStyle: {
          color: '#666666',
        },
        formatter: function (params) {
          var newParamsName = "";
          var paramsNameNumber = params.length;
          var provideNumber = 10;  //一行显示几个字
          var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
          if (paramsNameNumber > provideNumber) {
            for (var p = 0; p < rowNumber; p++) {
              var tempStr = "";
              var start = p * provideNumber;
              var end = start + provideNumber;
              if (p == rowNumber - 1) {
                tempStr = params.substring(start, paramsNameNumber);
              } else {
                tempStr = params.substring(start, end) + "\n";
              }
              newParamsName += tempStr;
            }

          } else {
            newParamsName = params;
          }
          return newParamsName
        },
      },
    },
    axisLabel: {
      // color: '#BDBDBE',
      show: true,
      interval: 0,
      textStyle: {
        color: '#999999',
        fontSize: '10'
      },
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#f3f4f5',
      },
    },
    axisTick: {
      alignWithLabel: true,
      show: false
    },
    series: series,
    dataset: dataset
  }
}
export function hengzhutu2(dataset) {
  let legendL = 0
  dataset.dimensions.forEach((val, index) => {
    if (val.length > legendL && index > 0) legendL = val.length
  })
  let color = ['#2574FA', '#FAA922', '#6DC9F6', 'rgba(156, 242, 237, 1)', 'rgba(109, 201, 246, 1)']
  let series = []
  dataset.series.forEach((val, index) => {
    series.push({
      type: val.type,
      smooth: false,
      barGap: '0%',
      symbol: 'circle',
      stack: dataset.series[index].stack ? dataset.series[index].stack : '',
      // barWidth: dataset.dimensions.length > 4 ? 4 : 10,
      barMaxWidth: 18,
      itemStyle: {
        //柱形图圆角，鼠标移上去效果，如果只是一个数字则说明四个参数全部设置为那么多
        color: color[index],
        normal: {
          color: color[index],
          //柱形图圆角，初始化效果

        }
      },
      // tooltip: {
      //   valueFormatter: function (value) {
      //     return (value ? Math.abs(value) : '0') + val.unit+'213123';
      //   }
      // },
      lineStyle: {
        width: 2
      }
    })
  })
  return {
    color: ['#2574F9'],
    legend: {
      itemWidth: 10,
      show: dataset.dimensions.length > 2 ? true : false,
      left: 'center',
      bottom: 0,
      itemHeight: dataset.dimensions.length > 2 ? 6 : 15,
      textStyle: {
        color: '#000',
        width: 1,
        fontSize: legendL > 11 ? 10 : 12
      },
    },
    // dataZoom: [{type: 'inside',realtime: true,start: 0,end: 70}],
    tooltip: {
      trigger: 'axis',
      position: function (pos) {
        return [10, pos[1],]
      },
      show: true,
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: 'rgba(67, 67, 67, 1)',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
      formatter: function (params) {
        let str = ''
        if (params.length) {
          str = params[0].name
          params.forEach((val, index) => {
            str += `<br /> ${val.seriesName}: <span style="font-family: 'numbers';">${Math.abs(val.data[val.seriesName]) ? Math.abs(val.data[val.seriesName]) : '0'}</span>${(dataset.series[val.seriesIndex].unit && dataset.series[val.seriesIndex].unit !== 'null' ? dataset.series[val.seriesIndex].unit : '')}`
          })
        } else {
          str += params.name
          str += `<br /> ${params.seriesName}: <span style="font-family: 'numbers';">${Math.abs(params.data[params.seriesName]) ? Math.abs(params.data[params.seriesName]) : '0'}</span>${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}`
        }
        return str
      },
    },
    grid: {
      show: true,
      x: 0,
      y: 14,
      x2: 18,
      y2: dataset.series.length > 2 ? legendL > 10 ? Math.ceil(dataset.series.length) * 22 : Math.ceil(dataset.series.length / 2) * 22 : 22,
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    xAxis: {
      splitNumber: 5,
      type: 'value',
      axisLabel: {
        rotate: 50,
        color: '#BDBDBE',
        show: true,
        interval: 0,
        textStyle: {
          color: '#999999',
          fontSize: '12'
        },
        fontFamily: 'numbers',
        formatter: function (value) {
          return Math.abs(value)
        },
      },
      axisLine: {
        show: true,
        lineStyle: {
          color: '#f3f4f5',
        },
      },
      axisTick: {
        alignWithLabel: true,
        show: true
      },
      splitLine: { //网格线
        lineStyle: {
          type: 'dashed', //设置网格线类型 dotted：虚线 solid:实线
          color: "#eeeeee",
        },
        show: true //隐藏或显示
      }
    },
    yAxis: {
      splitNumber: 5,
      type: 'category',
      axisLine: {
        show: false,
      },
      axisTick: {
        show: false
      },
      axisLabel: {
        formatter: function (params) {
          var newParamsName = "";
          var paramsNameNumber = params.length;
          var provideNumber = 9;  //一行显示几个字
          var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
          if (paramsNameNumber > provideNumber) {
            for (var p = 0; p < rowNumber; p++) {
              var tempStr = "";
              var start = p * provideNumber;
              var end = start + provideNumber;
              if (p == rowNumber - 1) {
                tempStr = params.substring(start, paramsNameNumber);
              } else {
                tempStr = params.substring(start, end) + "\n";
              }
              newParamsName += tempStr;
            }

          } else {
            newParamsName = params;
          }
          return newParamsName
        },
      },
    },
    axisLabel: {
      rotate: 0,
      // color: '#BDBDBE',
      show: true,
      interval: 0,
      textStyle: {
        color: '#999999',
        fontSize: '10'
      },
    },
    axisLine: {
      show: true,
      lineStyle: {
        color: '#f3f4f5',
      },
    },
    axisTick: {
      alignWithLabel: true,
      show: false
    },
    series: series,
    dataset: dataset
  }
}

//旭日图  
export function xuritu(dataset) {

  return {
    color: ['#0293ED', '#009DFF', '#2574FA', '#3387F8', '#2ECD3A', '#42D94E'],
    series: {
      type: 'sunburst',
      data: dataset.source,
      radius: [0, '90%'],
      label: {
        rotate: 'radial'
      },
      levels: [
        {},
        {
          r0: '10%',
          r: '60%',
          label: {
            rotate: 'center',
          },
        },
        {
          r0: '60%',
          r: '100%',
          label: {
            align: 'center',
            color: '#fff',
          },
        }
      ],
    }
    // dataset: dataset
  }
}

// 仪表盘
export function yibiaopan(dataset) {
  let num = dataset.source[0][dataset.dimensions[1]] ? dataset.source[0][dataset.dimensions[1]] : '0'
  const color1 = [
    [0.4, "#2574FA"],
    [0.8, "#25A8FA"],
    [1, "#FAA922"]
  ];
  const data1 = [{
    name: "",
    value: num,
  }];
  return {
    tooltip: { //配置提示框组件
      show: false,
      formatter: "{b}：{c}%",
      fontFamily: 'numbers',
      borderColor: "#333", //设置提示框浮层的边框颜色
      borderWidth: 0, //设置提示框浮层的边框宽
      padding: 5, //设置提示框浮层内边距，单位px，默认各方向内边距为5
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: 'rgba(67, 67, 67, 1)',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
    },
    title: { //配置标题组件
      text: '',
      x: 'center',
      y: 25,
      show: true, //设置是否显示标题，默认true
      //设置相对于仪表盘中心的偏移位置
      //数组第一项是水平方向的偏移，第二项是垂直方向的偏移
      offsetCenter: [50, "20%"],
      textStyle: {
        fontFamily: 'numbers', //设置字体名称，默认宋体
        color: "blue", //设置字体颜色，默认#333
        fontSize: 12, //设置字体大小，默认15
      }
    },
    series: [{
      name: "单仪表盘示例", //设置系列名称，用于tooltip的显示，legend的图例筛选
      type: "gauge", //设置系列类型
      radius: "85%", //设置参数：number，string，仪表盘半径，默认75%
      center: ["50%", "55%"], //设置仪表盘位置(圆心坐标)
      startAngle: 225, //设置仪表盘起始角度，默认225
      endAngle: -45, //设置仪表盘结束角度，默认-45
      clockwise: true, //设置仪表盘刻度是否是顺时针增长，默认true
      min: 0, //设置最小的数据值，默认0，映射到minAngle
      max: 100, //设置最大的数据值，默认100，映射到maxAngle
      splitNumber: 10, //设置仪表盘刻度的分割段数，默认10
      axisLine: { //设置仪表盘轴线(轮廓线)相关配置
        show: true, //设置是否显示仪表盘轴线(轮廓线)，默认true
        lineStyle: { //设置仪表盘轴线样式
          color: color1, //设置仪表盘的轴线可以被分成不同颜色的多段
          opacity: 1, //设置图形透明度，支持从0到1的数字，为0时不绘制该图形
          width: 20, //设置轴线宽度，默认30
          shadowBlur: 20, //设置(发光效果)图形阴影的模糊大小
          shadowColor: "#fff", //设置阴影颜色，支持的格式同color
        }
      },
      splitLine: { //设置分隔线样式
        show: false, //设置是否显示分隔线，默认true
        length: 0, //设置分隔线线长，支持相对半径的百分比，默认30
        lineStyle: { //设置分隔线样式
          color: "#eee", //设置线的颜色，默认#eee
          //设置图形透明度，支持从0到1的数字，为0时不绘制该图形
          opacity: 1,
          width: 1, //设置线度，默认2
          type: "solid", //设置线的类型，默认solid，此外还有dashed，dotted
          shadowBlur: 0, //设置(发光效果)图形阴影的模糊大小
          shadowColor: "#fff", //设置阴影颜色，支持的格式同color
        }
      },
      axisTick: { //设置刻度(线)样式
        show: false, //设置是否显示刻度(线)，默认true
        splitNumber: 5, //设置分隔线之间分割的刻度数，默认5
        length: 8, //设置刻度线长.支持相对半径的百分比，默认8
        lineStyle: { //设置刻度线样式
          color: "#eee", //设置线的颜色，默认#eee
          //设置图形透明度.支持从0到1的数字，为0时不绘制该图形
          opacity: 1,
          width: 1, //设置线度，默认 1
          type: "solid", //设置线的类型，默认solid，此外还有dashed，dotted
          shadowBlur: 10, //设置(发光效果)图形阴影的模糊大小
          shadowColor: "#fff", //设置阴影颜色，支持的格式同color
        },
      },
      axisLabel: { //设置刻度标签
        show: true, //设置是否显示标签，默认true
        distance: 22, //设置标签与刻度线的距离，默认5
        color: "rgba(153, 153, 153, 1)", //设置文字的颜色
        fontSize: 10, //设置文字的字体大小，默认5
        //设置刻度标签的内容格式器，支持字符串模板和回调函数两种形式
        formatter: "{value}",
        fontFamily: 'numbers',
      },
      pointer: { //设置仪表盘指针
        show: true, //设置是否显示指针，默认true
        //设置指针长度,可以是绝对值，也可是相对于半径的百分比，默认80%
        length: "70%",
        width: 3, //设置指针宽度，默认8
      },
      itemStyle: { //设置仪表盘指针样式
        color: "auto", //设置指针颜色，默认(auto)取数值所在的区间的颜色
        opacity: 1, //设置图形透明度，支持从0到1的数字，为0时不绘制该图形
        borderWidth: 0, //设置描边线宽,默认0，为0时无描边
        //设置柱条的描边类型,默认为实线，支持'solid'，'dashed'，'dotted'
        borderType: "solid",
        borderColor: "#000", //设置图形的描边颜色，默认"#000"，不支持回调函数
        shadowBlur: 10, //设置(发光效果)图形阴影的模糊大小
        shadowColor: "#fff", //设置阴影颜色，支持的格式同color
      },
      emphasis: { //设置高亮的仪表盘指针样式
        itemStyle: {
          //高亮和正常,两者具有同样的配置项，只是在不同状态下配置项的值不同
        }
      },
      detail: { //设置仪表盘详情，用于显示数据
        show: true, //设置是否显示详情，默认true
        offsetCenter: [0, "72%"], //设置相对于仪表盘中心的偏移位置
        color: "auto", //设置文字的颜色，默认auto
        fontSize: 18, //设置文字的字体大小，默认15
        color: "#000", //设置文字的颜色
        fontFamily: 'numbers',
        formatter: "{value}{c|%}", //格式化函数或者字符串
        rich: {
          a: {
            padding: [0, 0, 0, 10],
            fontFamily: 'numbers',
            fontSize: 20,
          },
          c: {
            padding: [0, 10, 0, 2],
            fontSize: 20,
            color: "#000",
            fontFamily: 'numbers',
          },
        },
      },
      data: data1
    }],

    dataset: dataset
  }
}

export function shuiditu(dataset) {
  let num = dataset.source[0][dataset.dimensions[1]] ? dataset.source[0][dataset.dimensions[1]] : '0'
  return {
    series: [
      {
        type: 'liquidFill',
        radius: '80%',
        //水波
        color: [
          '#def2fe',
          '#b6e3fc',
          new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
            offset: 0,
            color: "#72D1FB",
          }, {
            offset: 0.8,
            color: "#43ABF7",
          }
          ])],
        data: [num / 100, num / 100, num / 100],
        center: ['50%', '50%'],
        label: {
          normal: {
            formatter: num + '%',
            fontSize: 30,
            fontWeight: 400,
            color: '#72D1FB'
          }
        },
        itemStyle: {
          //opacity: 0.7, // 波浪的透明度
          shadowBlur: 0 // 波浪的阴影范围
        },
        emphasis: {
          itemStyle: {
            opacity: 0.8, // 鼠标经过波浪颜色的透明度
          },
        },
        outline: {
          borderDistance: 0,
          itemStyle: {
            borderWidth: 4,
            borderColor: '#ecebea',
            shadowBlur: 20
          }
        },
        backgroundStyle: {
          color: '#fff'
        }
      },
      {
        type: 'pie',
        center: ['50%', '50%'],
        radius: ['80%', '81%'],
        hoverAnimation: false,
        borderCap: 'round',
        data: [
          {
            name: '',
            value: num,
            labelLine: {
              show: false,
            },
            itemStyle: {
              normal: {
                borderColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#43ABF7'
                }, {
                  offset: 1,
                  color: '#72D1FB'
                }]),
                borderWidth: 4
              },
              emphasis: {
                borderColor: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                  offset: 0,
                  color: '#43ABF7'
                }, {
                  offset: 1,
                  color: '#72D1FB'
                }]),
                borderWidth: 5
              }
            },
            label: {
              normal: {
                show: false,
                position: 'center'
              }
            },
          },


          { //画中间的图标
            name: "",
            value: 0,
            label: {
              position: 'inside',
              backgroundColor: {
                image: ''

              },
              shadowColor: 'rgba(18, 64, 123, 0.38)',
              shadowBlur: 8,
              padding: 20,
              distance: 50
            }
          },
          {
            //画剩余的刻度圆环
            name: '',
            value: 100 - num,
            itemStyle: {
              normal: {
                color: '#ecebea',
              },
              emphasis: {
                color: '#ecebea',
              }
            },
            label: {
              normal: {
                show: false,
                position: 'center'
              }
            },
            labelLine: {
              normal: {
                show: false
              }
            }
          },
          // .
        ],
      }
    ]
  }
}

//地图  
export function ditu(dataset) {
  let pieces = dataset.pieces || []
  dataset.source.forEach(val => {
    let color = pieces.find(c => {
      if (!c.gte) {
        return val.value > c.lt
      }else if(!c.lt){
        return val.value <= c.gte
      }else {
        return val.value > c.lt && val.value <= c.gte
      }
    }).color
    val.color = color
  })
  return {
    visualMap: {
      show: false,
      type: 'piecewise',
      min: 0,
      max: 100,
      splitNumber: 1,
      bottom: '0',
      align: 'right',
      itemHeight: 10,
      // itemWidth: 15,
      textStyle: {
        color: '#555',
        fontWeight: 400,
        fontSize: '8px'
      },
      pieces: pieces
    },
    tooltip: {
      borderWidth: '0',
      padding: 8,
      enterable: true,
      transitionDuration: 1,
      fontFamily: 'numbers',
      backgroundColor: "rgba(255, 255, 255, 0.9)", //设置提示框浮层的背景颜色
      formatter: function (data) {
        let str = data.name + dataset.label + '<br />'
        data.data.valueList.forEach((val, index) => {
          str += `<div style="color:#2574FA">${val.name}: <span style="font-family: 'numbers, math'">${val.value ? val.value : 0}${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}</span></div>`
        })
        return str
      },
      textStyle: {
        color: 'rgba(67, 67, 67, 1)',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      }
    },
    geo: {
      map: 'shanxi',
      selectedMode: false,
      zoom: 1.0,
      aspectScale: 0.85, //地图长度比
      left: 'center',
      label: {
        show: true,
        color: '#000',
        fontWeight: 'bold',
        fontSize: 12
      },
      itemStyle: {
        color: '#E9F1FE',
        borderColor: '#8CA9DD'
      },
      emphasis: {
        focus: 'none',
        itemStyle: {
          // color: null
          color: dataset.series[0].color === '蓝' ? '#6DC9F6' : '#5291FB', ///////////////
        },
        label: {
          color: "#000"
        }
      },
    },
    series: {
      type: 'map',
      name: '检测',
      roam: false,
      geoIndex: 0,
      data: dataset.source
    }
  }
}

// 曲线图总和
export function quxiantu(dataset, chartType) {
  let barfloat = dataset.barfloat
  let legendL = 0
  dataset.dimensions.forEach((val, index) => {
    if (val.length > legendL && index > 0) legendL = val.length
  })

  let legendL2 = 0
  dataset.source.forEach((val, index) => {
    if (val[dataset.dimensions[0]].length > legendL2) legendL2 = val[dataset.dimensions[0]].length
  })
  let color = ['#2574F9', '#6DC9F6', '#FAA922', '#FF7E00', '#FF0001', '#00E400']
  let series = []
  dataset.series.forEach((val, index) => {
    series.push({
      type: val.type,
      smooth: false,
      barGap: '0%',
      symbol: 'circle',
      fontFamily: 'numbers',
      showSymbol: true,
      stack: dataset.series.stack ? dataset.series.stack : '',
      tooltip: {
        show: chartType == 1 ? false : true,
        valueFormatter: function (value) {
          return (value ? value : '0') + val.unit;
        },
      },
      itemStyle: {
        color: color[index],
        normal: {
          // barBorderRadius: 0,
          color: color[index],
          label: {
            show: chartType == 1 ? true : false,
            position: "top",
            formatter: function (p) {
              let str = `{a| ${p.data[p.seriesName]}${dataset.series[0].unit == '%' ? '%' : ''}}`
              return p.data[p.seriesName] ? str : '';
            },
            rich: {
              a: {
                color: '#000',
                padding: [0, 10, 0, 4],
                fontFamily: 'numbers',
                fontSize: 12,
                height: 22,
                backgroundColor: 'rgba(255,255,255,0.8)',
                borderRadius: 4,
                borderWidth: 1,
                borderColor: '#eeeeee'
              }
            },
          }
        }
      },
      /* areaStyle: index===0? {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: 'rgba(37, 116, 250, 0.4)'
        }, {
          offset: 1,
          color: 'rgba(37, 116, 250, 0)'
        }])
      } : {color: 'rgba(37, 116, 250, 0)'}, */
      lineStyle: {
        width: 2
      },
    })
  })
  return {
    title: {
      show: false,
      x: 'center',
      text: '',
      textStyle: {
        fontWeight: 700,
        fontSize: 18,
        color: '#fff',
      },
    },
    dataZoom: [{
      show: true,
      zoomLock: true,
      type: 'inside',
      realtime: true,
      startValue: dataset.source.length>365? dataset.source.length - 365 : 0,
      endValue: dataset.source.length//x轴少于6个数据，则显示全部，超过6个数据则显示前6个。
    }],
    tooltip: {
      trigger: 'axis',
      show: true,
      confine: true,
      position: function (pos, params, dom, rect, size) {
        // 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
        var obj = { top: 40 };
        obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5;
        return obj;
      },
      extraCssText: 'z-index: 0;box-shadow: 0 3px 10px 0px rgba(37,116,250,0.1);border-radius: 6px',
      formatter: function (params) {
        let str = ''
        if (params.length>0) {
          str = `<div style="color: #1A1A1A">`+params[0].name + (dataset.label?dataset.label:'')+`</div>`
          params.forEach((val, index) => {
            str += `<div style="display:flex;align-items: center;">
                      <div style="background:`+color[index]+`;width:6px;height:6px;border-radius:50%;margin-right:5px;"></div>
                      <div style="color:'#434343'";>${val.seriesName}: ${val.data[val.seriesName] ? val.data[val.seriesName] : '0'}</div>
                      ${(dataset.series[val.seriesIndex].unit && dataset.series[val.seriesIndex].unit !== 'null' ? dataset.series[val.seriesIndex].unit : '')}
                    </div>`
          })
        } else {
          str = `<div style="color: #1A1A1A">`+params.name + (dataset.label?dataset.label:'')+`</div>`
          str += `<div style="display:flex;align-items: center;">
                    <div style="background:`+color[0]+`;width:6px;height:6px;border-radius:50%;margin-right:5px;"></div>
                    <div style="color:'#434343'";>${params.seriesName}: ${params.data[params.seriesName] ? params.data[params.seriesName] : '0'}</div>
                    ${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}
                  </div>`
        }
        return str
      },
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: '#434343',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
    },
    color: [
      {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
          offset: 0,
          color: '#73A6FC'
        }, // 设置颜色渐变
        {
          offset: 1,
          color: '#2574F9'
        }
        ]
      }
    ],
    legend: {
      left: 'center',
      itemWidth: 10,
      // itemHeight: 6,
      bottom: 0,
      itemHeight: 10,
      textStyle: {
        color: '#000',
        width: 1,
        fontSize: legendL > 8 ? 10 : 12
      },
    },
    calculable: true,
    xAxis: {
      type: 'category',
      show: true,
      // boundaryGap: false, //坐标轴两边留白策略，类目轴和非类目轴的设置和表现不一样
      axisLabel: {
        // rotate: dataset.source.length > 5 && legendL2 > 5 ? 50 : 0,
        show: true,
        inside: false,
        textStyle: {
          color: '#666666',
          fontSize: '11'
        },
        margin: 8,
        interval: dataset.dimensions[1]==='储气量'?null:(index, value) => {
          // 此处返回 true 和 false
          if(value.includes('月')){
            return true
          }
          if(value.match(/\.1$/)){
            return true
          }else{
            return false
          }
        },
        formatter: dataset.dimensions[1]==='储气量'?null: (params) => {
          if(params.includes('月')){
            return params
          }
          if(params.match(/\.1$/)){
            return params
          }else{
            return ''
          }
        }
      },
      axisTick: {
        show: true,
      },
      axisLine: { //坐标轴轴线相关设置。数学上的x轴
        show: true,
        onZero: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        }
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)',
          width: 0,
        }
      },
      splitNumber: 5,
    },
    yAxis: {
      type: "value",
      // scale: true,
      name: dataset.series[0].unit ? '单位：(' + dataset.series[0].unit + ')' : '',
      nameTextStyle: {
        align: 'left',
        color: '#666666' //color: 'rgba(238, 238, 238, 1)'
      },
      splitNumber: 5,
      axisLabel: {
        formatter: '{a|{value}}',
        rich: {
          a: {
            fontFamily: 'numbers',
          },
        },
        margin: 5,
        textStyle: {
          color: '#666666',
          fontSize: '12'
        },
      },
      axisTick: {
        show: false

      },
      axisLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        },
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dotted',
          color: 'rgba(238, 238, 238, 1)',
          width: 1,
        }
      },
    },
    grid: {
      show: true,
      x: 4,
      y: chartType == 1 ? 30 : 30,
      x2: 14,
      y2: dataset.series.length > 2 ? legendL > 18 ? Math.ceil(dataset.series.length) * 22 : Math.ceil(dataset.series.length / 3) * 22 : 22,
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    series: series,
    dataset: dataset
  }
}
// 柱状图总和
export function duozhutu(dataset, chartType, flag) {
  let arrs = {}
  if (flag) {
    arrs = {
      symbol: 'none',
      data: [
        { yAxis: 50, lineStyle: { color: '#8BE8A6' }, label: { show: true, color: '#8BE8A6', position: 'insideStartTop', formatter: '优', fontSize: '10' } },
        { yAxis: 100, lineStyle: { color: '#F6EC78' }, label: { show: true, color: '#F6EC78', position: 'insideStartTop', formatter: '良', fontSize: '10' } },
        { yAxis: 150, lineStyle: { color: '#F6CD84' }, label: { show: true, color: '#F6CD84', position: 'insideStartTop', formatter: '轻度', fontSize: '10' } },
        { yAxis: 200, lineStyle: { color: '#E07A64' }, label: { show: true, color: '#E07A64', position: 'insideStartTop', formatter: '中度', fontSize: '10' } },
        { yAxis: 300, lineStyle: { color: '#989BF1' }, label: { show: true, color: '#989BF1', position: 'insideStartTop', formatter: '重度', fontSize: '10' } },
        { yAxis: 500, lineStyle: { color: '#A1668C' }, label: { show: true, color: '#A1668C', position: 'insideStartTop', formatter: '严重', fontSize: '10' } },
      ]
    }
  }
  let barfloat = dataset.barfloat
  let legendL = 0
  dataset.dimensions.forEach((val, index) => {
    if (val.length > legendL && index > 0) legendL = val.length
  })
  let legendL2 = 0
  dataset.source.forEach((val, index) => {
    if (val[dataset.dimensions[0]].length > legendL2) legendL2 = val[dataset.dimensions[0]].length
  })

  let color = ['#2574FA', '#6DC9F6', '#FAA922', '#34CBB7', '#5D97FB', '#FA6A22']
  let series = []
  dataset.series.forEach((val, index) => {
    series.push({
      type: val.type,
      smooth: false,
      barGap: '17%',
      symbol: 'circle',
      fontFamily: 'numbers',
      stack: dataset.series.stack ? dataset.series.stack : '',
      // barWidth: dataset.dimensions.length>3?6:8,
      barMaxWidth: 18,
      markLine: index === 0 ? arrs : {},
      tooltip: {
        valueFormatter: function (value) {
          return (value ? value : '0') + val.unit;
        }
      },
      itemStyle: {
        //柱形图圆角，鼠标移上去效果，如果只是一个数字则说明四个参数全部设置为那么多
        color: color[index],
        normal: {
          color: color[index],
          //柱形图圆角，初始化效果
          barBorderRadius: [2, 2, 0, 0],
        }
      },
      lineStyle: {
        width: 1.5
      }
    })
  })
  return {
    title: {
      show: false,
      x: 'center',
      text: '',
      textStyle: {
        fontWeight: 700,
        fontSize: 18,
        color: '#fff',
      },
    },
    dataZoom: [{
      show: true,
      type: 'inside',
      realtime: true,
      zoomLock: true,
      startValue: dataset.source.length>6? dataset.source.length - 6 : 0,
      endValue: dataset.source.length//x轴少于6个数据，则显示全部，超过6个数据则显示前6个。
    }],
    tooltip: {
      trigger: 'axis',
      show: true,
      confine: true,
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
      extraCssText: 'z-index: 0;box-shadow: 0 3px 10px 0px rgba(37,116,250,0.1);border-radius: 6px',
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: '#434343',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
      fontFamily: 'numbers',
      trigger: 'axis',
      position: function (pos, params, dom, rect, size) {
        // 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
        var obj = { top: 40 };
        obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5;
        return obj;
      },
      formatter: function (params) {
        let str = ''
        if (params.length>0) {
          str = `<div style="color: #1A1A1A">`+params[0].name + (dataset.label?dataset.label:'')+`</div>`
          params.forEach((val, index) => {
            str += `<div style="display:flex;align-items: center;">
                      <div style="background:`+color[index]+`;width:6px;height:6px;border-radius:50%;margin-right:5px;"></div>
                      <div style="color:'#434343'";>${val.seriesName}: ${val.data[val.seriesName] ? val.data[val.seriesName] : '0'}</div>
                      ${(dataset.series[val.seriesIndex].unit && dataset.series[val.seriesIndex].unit !== 'null' ? dataset.series[val.seriesIndex].unit : '')}
                    </div>`
          })
        } else {
          str = `<div style="color: #1A1A1A">`+params.name + (dataset.label?dataset.label:'')+`</div>`
          str += `<div style="display:flex;align-items: center;">
                    <div style="background:`+color[0]+`;width:6px;height:6px;border-radius:50%;margin-right:5px;"></div>
                    <div style="color:'#434343'";>${params.seriesName}: ${params.data[params.seriesName] ? params.data[params.seriesName] : '0'}</div>
                    ${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}
                  </div>`
        }
        return str
      },
    },
    color: [
      {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
          offset: 0,
          color: '#73A6FC'
        }, // 设置颜色渐变
        {
          offset: 1,
          color: '#2574F9'
        }
        ]
      }
    ],
    legend: {
      left: 'center',
      icon: 'rect',
      bottom: 0,
      itemWidth: 6,
      itemHeight: 6,
      textStyle: {
        color: '#000',
        width: 1,
        fontSize: legendL > 8 ? 10 : 12
      },
    },
    calculable: true,
    xAxis: {
      type: 'category',
      show: true,
      // boundaryGap: false, //坐标轴两边留白策略，类目轴和非类目轴的设置和表现不一样
      axisLabel: {
        rotate: dataset.source.length > 5 && legendL2 > 5 ? 50 : 0,
        show: true,
        inside: false,
        textStyle: {
          color: '#666666',
          fontSize: '11'
        },
        margin: 8,
        formatter: function (params) {
          var newParamsName = "";
          var paramsNameNumber = params.length;
          var provideNumber = 7;  //一行显示几个字
          var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
          if (paramsNameNumber > provideNumber && dataset.source.length < 9) {
            for (var p = 0; p < rowNumber; p++) {
              var tempStr = "";
              var start = p * provideNumber;
              var end = start + provideNumber;
              if (p == rowNumber - 1) {
                tempStr = params.substring(start, paramsNameNumber);
              } else {
                tempStr = params.substring(start, end) + "\n";
              }
              newParamsName += tempStr;
            }

          } else {
            newParamsName = params;
          }
          return newParamsName
        }
      },
      axisTick: {
        show: true,
      },
      axisLine: { //坐标轴轴线相关设置。数学上的x轴
        show: true,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        }
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)',
          width: 0,
        }
      },
      splitNumber: 5,
    },
    yAxis: {
      type: "value",
      name: dataset.series[0].unit ? '单位：(' + dataset.series[0].unit + ')' : '',
      // nameLocation: 'start',
      nameTextStyle: {
        color: '#666666', //color: 'rgba(238, 238, 238, 1)'
        align: 'left',
      },
      splitNumber: 5,
      min: 0,
      axisLabel: {
        formatter: '{a|{value}}',
        rich: {
          a: {
            fontFamily: 'numbers',
          },
        },
        margin: 5,
        textStyle: {
          color: '#666666',
          fontSize: '12'
        },
      },
      axisTick: {
        show: false

      },
      axisLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dotted',
          color: 'rgba(238, 238, 238, 1)',
          width: 1,
        }
      },
    },
    grid: {
      show: true,
      x: 0,
      y: 30,
      x2: 14,
      y2: dataset.series.length > 2 ? legendL > 18 ? Math.ceil(dataset.series.length) * 22 : Math.ceil(dataset.series.length / 3) * 22 : 22,
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    series: series,
    dataset: dataset
  }
}
//柱状图+折线图
export function zhezhuhunhe(dataset, flag) {
  let arrs = {}
  if (flag) {
    arrs = {
      symbol: 'none',
      data: [
        { yAxis: 50, lineStyle: { color: '#8BE8A6' }, label: { show: true, color: '#8BE8A6', position: 'insideStartTop', formatter: '优', fontSize: '10' } },
        { yAxis: 100, lineStyle: { color: '#F6EC78' }, label: { show: true, color: '#F6EC78', position: 'insideStartTop', formatter: '良', fontSize: '10' } },
        { yAxis: 150, lineStyle: { color: '#F6CD84' }, label: { show: true, color: '#F6CD84', position: 'insideStartTop', formatter: '轻度', fontSize: '10' } },
        { yAxis: 200, lineStyle: { color: '#E07A64' }, label: { show: true, color: '#E07A64', position: 'insideStartTop', formatter: '中度', fontSize: '10' } },
        { yAxis: 300, lineStyle: { color: '#989BF1' }, label: { show: true, color: '#989BF1', position: 'insideStartTop', formatter: '重度', fontSize: '10' } },
        { yAxis: 500, lineStyle: { color: '#A1668C' }, label: { show: true, color: '#A1668C', position: 'insideStartTop', formatter: '严重', fontSize: '10' } },
      ]
    }
  }
  let barfloat = dataset.barfloat
  let legendL = 0
  let label = dataset.label?dataset.label:''
  dataset.source.forEach((val, index) => {
    if (val[dataset.dimensions[0]].length > legendL) legendL = val[dataset.dimensions[0]].length
  })
  let colorStr = ''
  let color = ['#2574F9', 'rgba(109, 201, 246, 1)', 'rgba(76, 140, 250, 1)', '#FF7E00', '#FF0001', '#00E400']
  let series = []
  let specialColorSet = false
  dataset.series.forEach((val, index) => {
    if (val.type === 'line') {
      let colorList = ['#8BE8A6', '#FAA922', '#F6CD84', '#E07A64', '#989BF1', '#A1668C']
      colorStr = colorList[index]
    } else {
      colorStr = color[index]
    }
    series.push({
      markLine: index === 0 ? arrs : {},
      name: dataset.dimensions[index + 1],
      type: val.type,
      smooth: false,
      symbol: 'circle',
      barGap: '0%',
      stack: dataset.series.stack ? dataset.series.stack : '',
      // barWidth: 10,
      barMaxWidth: 10,
      yAxisIndex: index,
      showSymbol: true,
      tooltip: {
        // formatter: function (value) {
        //   return (value?value:'0') + val.unit
        // },
      },
      itemStyle: {
        //柱形图圆角，鼠标移上去效果，如果只是一个数字则说明四个参数全部设置为那么多
        color: color[index],
        normal: {
          color: colorStr,
          //柱形图圆角，初始化效果
          barBorderRadius: [3, 3, 0, 0],
        },
      },
      lineStyle: {
        width: 2,
        // type: 'dashed'
      }
      /* areaStyle: index===1? {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: 'rgba(109, 201, 246, 0.5)'
        }, {
          offset: 0.7,
          color: 'rgba(109, 201, 246, 0)'
        }])
      } : (index===2? {
        color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
          offset: 0,
          color: 'rgba(76, 140, 250, 0.5)'
        }, {
          offset: 0.7,
          color: 'rgba(37, 116, 250, 0)'
        }])
        } : {}), */
    })
  })
  let yAxis = []
  if (true) {
    let splitNumber = 5
    dataset.series.forEach((val, index) => {
      yAxis.push({
        type: "value",
        name: val.unit ? '单位：(' + val.unit + ')' : '',
        nameTextStyle: {
          align: index === 0 ? 'left' : 'right',
          color: '#666666' //color: 'rgba(238, 238, 238, 1)'
        },
        splitNumber: splitNumber,
        // interval: (max-min)/splitNumber,
        minInterval: 1,
        // scale:true,
        position: index === 1 ? 'right' : '',
        axisLabel: {
          formatter: '{a|{value}}',
          rich: {
            a: {
              fontFamily: 'numbers',
            },
          },
          textStyle: {
            color: '#666666',
            fontSize: '12',
          },
          margin: 5,
        },
        axisTick: {
          show: false
        },
        axisLine: {
          show: false,
          lineStyle: {
            color: 'rgba(238, 238, 238, 1)'
          }
        },
        splitLine: {
          show: false,
          lineStyle: {
            type: 'dotted',
            color: 'rgba(238, 238, 238, 1)',
            width: 1,
          }
        }
      })
    })
  }
  return {
    title: {
      show: false,
      x: 'center',
      text: '',
      textStyle: {
        fontWeight: 700,
        fontSize: 18,
        color: '#fff',
      },
    },
    // dataZoom: [{type: 'inside',realtime: true,start: dataset.source.length > 8 ? barfloat=='right'?(dataset.source.length > 23 ? 70 : 30) : 0: 0,end: dataset.source.length > 8 ? barfloat=='left'?(dataset.source.length > 23 ? 30 : 70) : 100: 100}],
    dataZoom: [{
      zoomLock: true,
      show: true,
      type: 'inside',
      realtime: true,
      startValue: dataset.source.length>12?dataset.source.length-12:0,
      endValue: dataset.source.length//x轴少于6个数据，则显示全部，超过6个数据则显示前6个。
    }],
    tooltip: {
      trigger: 'axis',
      show: true,
      confine: true,
      fontFamily: 'numbers',
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
      position: function (pos, params, dom, rect, size) {
        // 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
        var obj = { top: 40 };
        obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5;
        return obj;
      },
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: '#434343',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
      extraCssText: 'z-index: 0;box-shadow: 0 3px 10px 0px rgba(37,116,250,0.1);border-radius: 6px',
      // position: function (pos) {
      //   return [pos[0], '5%']
      // },
      formatter: function (params) {
        let str = ''
        if (params.length) {
          str = params[0].name + label
          params.forEach((val, index) => {
            str += `<br />${val.seriesName}: <span style="font-family: 'numbers';color:'#1A1A1A';">${val.data[val.seriesName] ? val.data[val.seriesName] : '0'}</span>${(dataset.series[val.seriesIndex].unit && dataset.series[val.seriesIndex].unit !== 'null' ? dataset.series[val.seriesIndex].unit : '')}`
          })
        } else {
          str += params.name + label
          str += `:<br />${params.seriesName}: <span style="font-family: 'numbers';color:'#1A1A1A';">${params.data[params.seriesName] ? params.data[params.seriesName] : '0'}</span>${(dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : '')}`
        }
        return str
      },
    },
    color: [
      {
        type: 'linear',
        x: 0,
        y: 0,
        x2: 0,
        y2: 1,
        colorStops: [{
          offset: 0,
          color: '#73A6FC'
        }, // 设置颜色渐变
        {
          offset: 1,
          color: '#2574F9'
        }
        ]
      }
    ],
    legend: {
      show: !specialColorSet,
      left: 'center',
      // icon: 'rect',
      bottom: 0,
      itemWidth: 10,
      itemHeight: dataset.dimensions.length > 4 ? 4 : 10,
      textStyle: {
        color: '#000',
        width: 1,
        fontSize: legendL > 8 ? 10 : 12
      },
      data: null,
    },
    calculable: true,
    xAxis: {
      type: 'category',
      show: true,
      // boundaryGap: false, //坐标轴两边留白策略，类目轴和非类目轴的设置和表现不一样
      axisLabel: {
        rotate: dataset.source.length > 4 && legendL > 5 ? 50 : 0,
        show: true,
        inside: false,
        textStyle: {
          color: '#666666',
          fontSize: '10'
        },
        margin: 8,
        formatter: function (params) {
          var newParamsName = "";
          var paramsNameNumber = params.length;
          var provideNumber = 7;  //一行显示几个字
          var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
          if (paramsNameNumber > provideNumber && dataset.source.length < 9) {
            for (var p = 0; p < rowNumber; p++) {
              var tempStr = "";
              var start = p * provideNumber;
              var end = start + provideNumber;
              if (p == rowNumber - 1) {
                tempStr = params.substring(start, paramsNameNumber);
              } else {
                tempStr = params.substring(start, end) + "\n";
              }
              newParamsName += tempStr;
            }

          } else {
            newParamsName = params;
          }
          return newParamsName
        }
      },
      axisTick: {
        show: true,
      },
      axisLine: { //坐标轴轴线相关设置。数学上的x轴
        show: true,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        }
      },
      splitLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)',
          width: 0,
        }
      },
    },
    yAxis: yAxis,
    grid: {
      show: true,
      x: 0,
      y: 30,
      x2: 14,
      y2: specialColorSet ? 6 : (dataset.series.length > 2 ? legendL > 18 ? Math.ceil(dataset.series.length) * 22 : Math.ceil(dataset.series.length / 3) * 22 : 26),
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    series: series,
    dataset: dataset
  }
}

//渐变单柱状图
export function zhutu(dataset, flag) {
  let arrs = {}
  if (flag) {
    arrs = {
      symbol: 'none',
      data: [
        { yAxis: 50, lineStyle: { color: '#8BE8A6' }, label: { show: true, color: '#8BE8A6', position: 'insideStartTop', formatter: '优', fontSize: '10' } },
        { yAxis: 100, lineStyle: { color: '#F6EC78' }, label: { show: true, color: '#F6EC78', position: 'insideStartTop', formatter: '良', fontSize: '10' } },
        { yAxis: 150, lineStyle: { color: '#F6CD84' }, label: { show: true, color: '#F6CD84', position: 'insideStartTop', formatter: '轻度', fontSize: '10' } },
        { yAxis: 200, lineStyle: { color: '#E07A64' }, label: { show: true, color: '#E07A64', position: 'insideStartTop', formatter: '中度', fontSize: '10' } },
        { yAxis: 300, lineStyle: { color: '#989BF1' }, label: { show: true, color: '#989BF1', position: 'insideStartTop', formatter: '重度', fontSize: '10' } },
        { yAxis: 500, lineStyle: { color: '#A1668C' }, label: { show: true, color: '#A1668C', position: 'insideStartTop', formatter: '严重', fontSize: '10' } },
      ]
    }
  }
  let barfloat = dataset.barfloat
  let legendL2 = 0
  dataset.source.forEach((val, index) => {
    if (val[dataset.dimensions[0]].length > legendL2) legendL2 = val[dataset.dimensions[0]].length
  })
  return {
    color: ['#2574F9'],
    legend: {
      itemWidth: 6,
      itemHeight: 6,
      left: 'center',
      bottom: -5,
      icon: 'rect',
    },
    grid: {
      show: true,
      x: 0,
      y: 30,
      x2: 14,
      y2: dataset.series.length > 2 ? Math.ceil(dataset.series.length / 3) * 22 : 22,
      borderWidth: 0,
      containLabel: true,
      backgroundColor: 'rgba(8,58,200,.0)',
      borderWidth: '0', //去掉最外部边框
    },
    color: [{
      type: 'linear',
      x: 0,
      y: 0,
      x2: 0,
      y2: 1,
      colorStops: [{
        offset: 0,
        color: '#73A6FC'
      }, // 设置颜色渐变
      {
        offset: 1,
        color: '#2574FA'
      }
      ]
    }
    ],
    tooltip: {
      trigger: 'axis',
      axisPointer: {
        lineStyle: {
          color: 'rgba(115, 166, 252, 1)',
          type: 'dashed'
        }
      },
      position: function (pos, params, dom, rect, size) {
        // 鼠标在左侧时 tooltip 显示到右侧，鼠标在右侧时 tooltip 显示到左侧。
        var obj = { top: 40 };
        obj[['left', 'right'][+(pos[0] < size.viewSize[0] / 2)]] = 5;
        return obj;
      },
      formatter: function (data) {
        return `${data[0].name}<br/>${data[0].seriesName}: <span style="font-family: 'numbers';">${data[0].data[data[0].seriesName] ? data[0].data[data[0].seriesName] : '0'}</span> ${dataset.series[0].unit && dataset.series[0].unit !== 'null' ? dataset.series[0].unit : ''}`; //将小数转化为百分数显示
      },
      extraCssText: 'z-index: 0;box-shadow: 0 3px 10px 0px rgba(37,116,250,0.1);border-radius: 6px',
      backgroundColor: "rgba(255, 255, 255, 0.9)",
      textStyle: {
        color: '#434343',
        fontWeight: 700,
        fontSize: 12,
        decoration: 'none'
      },
    },
    dataZoom: [{
      zoomLock: true,
      show: true,
      type: 'inside',
      realtime: true,
      startValue: dataset.source.length>6? dataset.source.length - 6 : 0,
      endValue: dataset.source.length//x轴少于6个数据，则显示全部，超过6个数据则显示前6个。
    }],
    xAxis: {
      type: 'category',
      //   data: ['省直', '太原市', '大同市', '阳泉市', '长治市', '晋城市', '朔州市', '晋中市', '运城市', '忻州市', '临汾市', '吕梁市'],
      axisLabel: {
        rotate: dataset.source.length > 5 && legendL2 > 5 ? 50 : 0,
        textStyle: {
          color: '#666666',
          fontSize: '11'
        },
        inside: false,
        show: true,
        interval: 0,
        formatter: function (params) {
          var newParamsName = "";
          var paramsNameNumber = params.length;
          var provideNumber = 7;  //一行显示几个字
          var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
          if (paramsNameNumber > provideNumber && dataset.source.length < 9) {
            for (var p = 0; p < rowNumber; p++) {
              var tempStr = "";
              var start = p * provideNumber;
              var end = start + provideNumber;
              if (p == rowNumber - 1) {
                tempStr = params.substring(start, paramsNameNumber);
              } else {
                tempStr = params.substring(start, end) + "\n";
              }
              newParamsName += tempStr;
            }

          } else {
            newParamsName = params;
          }
          return newParamsName
        }
      },
      axisTick: {
        show: false,
        inside: true,
        alignWithLabel: true
        // length: axisTicklength
      },
      axisLine: { //坐标轴轴线相关设置。数学上的x轴
        show: true,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        }
      },
    },
    yAxis: {
      type: "value",
      name: dataset.series[0].unit ? '单位：(' + dataset.series[0].unit + ')' : '',
      nameTextStyle: {
        align: 'left',
        color: '#666666' //color: 'rgba(238, 238, 238, 1)'
      },
      splitNumber: 5,
      splitLine: { //网格线
        lineStyle: {
          type: 'dashed',//设置网格线类型 dotted：虚线 solid:实线
          color: "#eeeeee",
        },
        show: true //隐藏或显示
      },
      axisLabel: {
        formatter: '{a|{value}}',
        rich: {
          a: {
            fontFamily: 'numbers',
          },
        },
        interval: 1,
        margin: 5,
        textStyle: {
          color: '#666666',
          fontSize: '12'
        },
      },
      axisTick: {
        show: false
      },
      axisLine: {
        show: false,
        lineStyle: {
          color: 'rgba(238, 238, 238, 1)'
        }
      },
      splitLine: {
        show: true,
        lineStyle: {
          type: 'dotted',
          color: 'rgba(238, 238, 238, 1)',
          width: 1,
        }
      }
    },
    series: [
      {
        // name: '营业利润率',
        type: 'bar',
        barWidth: 18,
        markLine: arrs,
        tooltip: {
          show: true,
          valueFormatter: function (value) {
            return (value ? value : '0') + value.unit;
          }
        },
        // itemStyle: {
        //   //柱形图圆角，鼠标移上去效果，如果只是一个数字则说明四个参数全部设置为那么多
        //   normal: {
        //     //柱形图圆角，初始化效果
        //     barBorderRadius: [4, 4, 0, 0],
        //   }
        // },
        itemStyle: {
          // color: color[index],
          normal: {
            barBorderRadius: [4, 4, 0, 0],
            // color: color[index],
            label: {
              show: false,
              position: "top",
              formatter: function (p) {
                let str = `{a| ${p.data[p.seriesName]}${dataset.series[0].unit == '%' ? '%' : ''}}`
                return p.data[p.seriesName] ? str : '';
              },
              rich: {
                a: {
                  color: '#000',
                  padding: [0, 10, 0, 4],
                  // fontFamily: 'numbers',
                  fontSize: 12,
                  height: 22,
                  backgroundColor: 'rgba(255,255,255,0.8)',
                  borderRadius: 4,
                  borderWidth: 1,
                  borderColor: '#eeeeee'
                }
              },
            }
          }
        },
        smooth: false,
      }
    ],
    dataset: dataset
  }
}
